package main

import (
	"fmt"
	"log"
	"os"
	"strings"
	"sync"
)

func main() {

	filenames := []string{"ADB.txt", "Test.txt", "test2.txt"}
	fmt.Println("total", makeLower(filenames))
}

// 统计长度
func makeLower(filenames []string) int64 {
	sizes := make(chan int64)

	var wg sync.WaitGroup

	for _, f := range filenames {
		wg.Add(1)
		go func(f string) {
			defer wg.Done()
			lower, err := toLower(f)
			if err != nil {
				log.Fatal(err)
				return
			}
			stat, err := os.Stat(lower)
			if err != nil {
				log.Fatal(err)
				return
			}
			sizes <- stat.Size()
		}(f)
	}

	go func() {
		wg.Wait()
		close(sizes)
	}()

	var total int64
	for size := range sizes {
		total += size
	}
	return total
}

func toLower(name string) (tName string, err error) {
	return strings.ToLower(name), nil
}
